local beta = 1/1.03

//second round of counterfactual analysis: cost-benefit analysis
import delimited "$model/simulated_data/simulated_data_base.csv", clear
ren v5 t
ren v17 tax
ren v21 gov_exp
replace gov_exp = 0 if t!=23

keep t tax gov_exp

gen disc = t - 17
replace tax = tax * (`beta'^disc)


collapse (sum) gov_exp tax
gen uniqid = 1
gen npv = tax - gov_exp
save "$temp/cba_baseline", replace

import delimited "$model/simulated_data/simulated_data_rec_nopol.csv", clear
ren v5 t
ren v17 tax
ren v21 gov_exp
replace gov_exp = 0 if t!=23

gen disc = t - 17
replace tax = tax * (`beta'^disc)

collapse (sum) gov_exp tax
gen npv = tax - gov_exp
gen uniqid = 1
save "$temp/cba_rec", replace

//CBA for the Real-World Recession Policies



//CBA for the various Pell policies
qui{
forval i = 1/4{
	
	//baseline
	import delimited "$model/simulated_data/simulated_data_cfact_`i'_pbr_0_rec_0.csv", clear
	ren v5 t
	ren v17 tax
	ren v21 gov_exp
	replace gov_exp = 0 if t!=23
	
	gen disc = t - 17
	replace tax = tax * (`beta'^disc)
	
	collapse (sum) gov tax
	gen uniqid = 1
	
	ren gov_exp gov_exp_cfact
	ren tax tax_cfact
	merge 1:1 uniqid using "$temp/cba_baseline", keep(match) nogen
	gen npv_cfact =  tax_cfact - gov_exp_cfact
	gen change_npv = npv_cfact - npv
	gen change_npv_percap = (change_npv * 40000) / (50000 * 1000) // per capita change, thousands of dollars
	su change_npv_percap
	local r1 = round(`r(mean)', 0.01)

	//recession
	import delimited "$model/simulated_data/simulated_data_cfact_`i'_pbr_1_rec_0.csv", clear
	ren v5 t
	ren v17 tax
	ren v21 gov_exp
	replace gov_exp = 0 if t!=23
	
	gen disc = t - 17
	replace tax = tax * (`beta'^disc)
	
	collapse (sum) gov tax
	gen uniqid = 1
	ren gov_exp gov_exp_cfact
	ren tax tax_cfact
	merge 1:1 uniqid using "$temp/cba_baseline", keep(match) nogen
	gen npv_cfact =  tax_cfact - gov_exp_cfact
	gen change_npv = npv_cfact - npv
	gen change_npv_percap = (change_npv * 40000) / (50000 * 1000) // per capita change, thousands of dollars
	su change_npv_percap
	local r2 = round(`r(mean)', 0.01)
	
	//baseline, no pbr
	import delimited "$model/simulated_data/simulated_data_cfact_`i'_pbr_0_rec_1.csv", clear
	ren v5 t
	ren v17 tax
	ren v21 gov_exp
	replace gov_exp = 0 if t!=23
	
	gen disc = t - 17
	replace tax = tax * (`beta'^disc)
	
	collapse (sum) gov tax
	gen uniqid = 1
	ren gov_exp gov_exp_cfact
	ren tax tax_cfact
	merge 1:1 uniqid using "$temp/cba_rec", keep(match) nogen
	gen npv_cfact =  tax_cfact - gov_exp_cfact
	gen change_npv = npv_cfact - npv
	gen change_npv_percap = (change_npv * 40000) / (50000 * 1000) // per capita change, thousands of dollars
	su change_npv_percap
	local r3 = round(`r(mean)', 0.01)

	//recession, no pbr
	import delimited "$model/simulated_data/simulated_data_cfact_`i'_pbr_1_rec_1.csv", clear
	ren v5 t
	ren v17 tax
	ren v21 gov_exp
	replace gov_exp = 0 if t!=23
	
	gen disc = t - 17
	replace tax = tax * (`beta'^disc)
	
	
	collapse (sum) gov tax	
	gen uniqid = 1
	ren gov_exp gov_exp_cfact
	ren tax tax_cfact
	merge 1:1 uniqid using "$temp/cba_rec", keep(match) nogen
	gen npv_cfact =  tax_cfact - gov_exp_cfact
	gen change_npv = npv_cfact - npv
	gen change_npv_percap = (change_npv * 40000) / (50000 * 1000) // per capita change, thousands of dollars
	su change_npv_percap
	local r4 = round(`r(mean)', 0.01)
	
	//report
	noi di " & `r1' & `r2' & `r3' & `r4' \\"
}
}


//